package com.ssm.count.rpc.service.routingRecord;

import com.github.pagehelper.PageInfo;
import com.ssm.count.dao.mapper.routingRecord.RoutingrecordDao;
import com.ssm.count.dao.model.routingRecord.Routingrecord;
import com.ssm.count.rpc.api.routingRecord.RoutingrecordService;
import com.ssm.upms.dao.mapper.ssm.AccountDao;
import com.ssm.upms.dao.mapper.ssm.AdminDao;
import com.ssm.upms.dao.model.Admin;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
* 巡检记录管理 Service
* @author GaoXiang
* @version 1.0
*/
@Service
public class RoutingrecordServiceImpl implements RoutingrecordService {

    @Resource
    private RoutingrecordDao routingrecordDao;

    @Resource
    private AccountDao accountDao;

   /* @Resource
    private EstateDao estateDao;

    @Resource
    private EquipmentDao equipementDao;

    @Resource
    private ResidenceDao residenceDao;
    @Resource
    private BuildingDao buildingDao;
    @Resource
    private UnitDao unitDao;
*/
    @Resource
    private AdminDao adminDao;


    /**
    * 保存数据
    * @param routingrecord 实体对象
    * @return 实体id
    * @throws Exception 数据保存异常
    */
    public Integer insert(Routingrecord routingrecord) throws Exception {
        return routingrecordDao.insert(routingrecord);
    }

    /**
    * 根据 id 修改
    * @param routingrecord 带id的实体对象
    * @return 受影响的行数
    * @throws Exception 数据修改异常
    */
    public Integer updateById(Routingrecord routingrecord) throws Exception {
        return routingrecordDao.updateById(routingrecord);
    }

    /**
    * 根据 id 删除
    * @param id 数据id
    * @return 受影响的行数
    * @throws Exception 数据删除异常
    */
    public Integer deleteById(String id) throws Exception {
        return routingrecordDao.deleteById(id);
    }

    /**
    * 根据 id 查找
    * @param id 实体id
    * @return 实体
    */
    public Routingrecord selectById(String id) {
        return routingrecordDao.selectById(id);
    }

    /**
    * 根据 id 批量删除
    * @param ids 要删除的id
    * @return 影响的行数
    * @throws Exception 数据删除异常
    */
    public Integer deleteByIds(List<String> ids) throws Exception {
        return routingrecordDao.deleteByIds(ids);
    }

    /**
    * 查询列表
    * @param map 参数
    * @return 列表
    */
    public PageInfo<Routingrecord> list(Map map) {
        return routingrecordDao.list(map);
    }

    /**
    * 查询列表 带分页
    * @param map 参数
    * @param page 页码
    * @param size 每页大小
    * @return 列表
    */
    public PageInfo<Routingrecord> list(Map map,int page,int size) {
        PageInfo<Routingrecord> routingrecordPageInfo=routingrecordDao.list(map,page,size);
        for(Routingrecord r:routingrecordPageInfo.getList()){
            if(r.getType().equals("0")){//管理员
                Admin admin =adminDao.selectById(r.getAccountId());
               if(admin !=null){
                   r.setAccountName(admin.getName());
               }
            }/*else if(r.getType().equals("1")){//物业
                Estate estate=estateDao.selectById(r.getAccountId());
                if(estate !=null){
                    r.setEstateName(estate.getName());
                }
            }*/
          /* Equipment equipment= equipementDao.selectById(r.getEquipmentId());
            if(equipment!=null){
                r.setEquipmentNumber(equipment.getNumber());
                r.setResidenceName(residenceDao.selectById(equipment.getResidenceId()).getName());
                r.setBuildingNumber(buildingDao.selectById(equipment.getBuildingId()).getNumber());
                r.setUnitNumber(unitDao.selectById(equipment.getUnitId()).getNumber());
            }*/
        }
        return routingrecordPageInfo;
    }


}
